<template>
  <Editor
    :value="value"
    :mode="mode"
    :plugins="plugins"
    @change="handlerChange"
  />
  <!-- 用户在编辑器中输入，会触发handleChange-->
</template>

<script setup lang="ts">
import gfm from "@bytemd/plugin-gfm"; //引入支持列表，表格，删除线组件
import highlight from "@bytemd/plugin-highlight";
import { Editor, Viewer } from "@bytemd/vue-next"; //引入编辑器和视图查看器
import { ref, withDefaults, defineProps } from "vue";

/**
 * 定义组件属性
 *
 * 父组件操作子组件，给子组件传值
 */
interface Props {
  value: string; //由父级指定
  mode?: string;
  handlerChange: (v: string) => void;
}

const plugins = [
  gfm(),
  highlight(),
  // Add more plugins here
];

const props = withDefaults(defineProps<Props>(), {
  value: () => "",
  mode: () => "split",
  handlerChange: (v: string) => {
    console.log(v);
  },
});
</script>

<style>
.bytemd-toolbar-icon.bytemd-tippy.bytemd-tippy-right:last-child {
  display: none;
}
</style>
